package main;

public class RockPaperScissors {

	
	public RockPaperScissors() {
		
	}
	/*
	 * return Result.WIN if p1 wins, Result.LOST if p1 lost and Result.TIE if no one wins
	 */
	Result play(RPSEnum p1, RPSEnum p2)
	{
		Result r = Result.LOST;
		
		switch(p1)
		{
			case PAPER:
				switch (p2) {
					case PAPER:
						r = Result.TIE;
					break;
					case SCISSORS:
						r = Result.LOST;
					break;
					case ROCK:
						r = Result.WIN;
					break;

				}
			break;
			
			case ROCK:
				switch (p2) {
					case PAPER:
						r = Result.LOST;
					break;
					case SCISSORS:
						r = Result.WIN;
					break;
					case ROCK:
						r = Result.TIE;
					break;

				}
			break;
			
			case SCISSORS:
				switch (p2) {
					case PAPER:
						r = Result.WIN;
					break;
					case SCISSORS:
						r = Result.TIE;
					break;
					case ROCK:
						r = Result.LOST;
					break;

				}
			break;
		}
		
		return r;
	}
	/*
	 * return Result.WIN if p1 wins, Result.LOST if p1 lost and Result.TIE if no one wins
	 */
	Result play(Player p1, Player p2)
	{
		for (int i=0 ; i<p1.getSizeOfMoves() ; i++)
		{
			Result r = this.play(p1.getNextMove(), p2.getNextMove());
			if (r==Result.WIN)
			{
				p1.setScore(p1.getScore()+1);
			}	
			if (r==Result.LOST)
			{
				p2.setScore(p2.getScore()+1);
			}
			if (r==Result.TIE)
			{
				p1.setScore(p1.getScore()+1);
				p2.setScore(p2.getScore()+1);
			}
		}
		
		if (p1.getScore() > p2.getScore())
			return Result.WIN;
		else if (p1.getScore() < p2.getScore())
			return Result.LOST;
		else return Result.TIE;
	}
}
